package cn.thornbird.orgsync.vo.record;

import cn.thornbird.orgsync.constraints.NotNullCaseWhen;
import cn.thornbird.orgsync.entity.Task;
import cn.thornbird.orgsync.entity.status.AppType;
import cn.thornbird.orgsync.entity.status.TaskFrequency;
import lombok.Data;

import javax.validation.constraints.*;

@Data
@NotNullCaseWhen(source = "frequency", sourceValues = { (short) 2, (short) 3}, targets = { "dayOfWeek", "dayOfMonth" },
        message = "当同步频率为周或月时，对应字段不能为空")
public class TaskRecord extends Record<Task> {

    @NotBlank(message = "标题不能为空")
    @Size(max = 128, message = "标题长度不符合要求")
    private String title;

    private String userId;

    @NotBlank(message = "来源公司ID不能为空")
    @Size(max = 32, message = "来源公司ID长度不符合要求")
    private String sourceCompanyId;

    @NotNull(message = "来源应用类型不能为空")
    private AppType sourceAppType;

    @Size(max = 64, min = 1, message = "来源部门ID长度不符合要求")
    private String sourceDepartmentId;

    private String sourceDepartmentName;

    @NotBlank(message = "目标公司ID不能为空")
    @Size(max = 32, message = "目标公司ID长度不符合要求")
    private String targetCompanyId;

    @NotNull(message = "目标应用类型不能为空")
    private AppType targetAppType;

    @Size(max = 64, min = 1, message = "目标部门ID长度不符合要求")
    private String targetDepartmentId;

    private String targetDepartmentName;

    @Size(max = 16, min = 6, message = "默认密码不符合要求")
    private String defaultPassword;

    @NotNull(message = "包含子部门不能为空")
    private Boolean includingChildren;

    @NotNull(message = "包含雇员不能为空")
    private Boolean includingEmployees;

    @NotNull(message = "删除不存在的子部门不能为空")
    private Boolean deleteNonExistentChildren;

    @NotNull(message = "可用不能为空")
    private Boolean active;

    @NotNull(message = "同步频率不能为空")
    private TaskFrequency frequency;

    @Max(value = 6, message = "执行日(星期)超出范围(0-6)")
    @Min(value = 0, message = "执行日(星期)超出范围(0-6)")
    private Short dayOfWeek;

    @Max(value = 31, message = "执行日(月)超出范围(-31-31)")
    @Min(value = -31, message = "执行日(月)超出范围(-31-31)")
    private Short dayOfMonth;

    @NotNull(message = "执行时间(小时)不能为空")
    @Max(value = 23, message = "执行时间(小时)超出范围(0-23)")
    @Min(value = 0, message = "执行时间(小时)超出范围(0-23)")
    private Short hour;

    @NotNull(message = "执行时间(分钟)不能为空")
    @Max(value = 59, message = "执行时间(分钟)超出范围(0-59)")
    @Min(value = 0, message = "执行时间(分钟)超出范围(0-59)")
    private Short minute;

    @NotNull(message = "最大重试次数不能为空")
    @Max(value = 10, message = "最大重试次数超出范围(0-10)")
    @Min(value = 0, message = "最大重试次数超出范围(0-10)")
    private Short maxRetryCount;

    @NotNull(message = "重试间隔不能为空")
    @Max(value = 60, message = "重试间隔超出范围(0-60)")
    @Min(value = 0, message = "重试间隔超出范围(0-60)")
    private Short retryInterval;

    @Size(max = 256, message = "备注长度不符合要求")
    private String remark;

}
